package com.yang.service.adminimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yang.bean.MarketLog;
import com.yang.bean.MarketLogExample;
import com.yang.bean.common.CommonData;
import com.yang.mapper.MarketLogMapper;
import com.yang.service.admin.AdminLogService;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dinghongrui
 * @create 2022/09/07 14:45
 */
@Service
public class AdminLogServiceImpl implements AdminLogService {
    @Autowired
    MarketLogMapper marketLogMapper;

    @Override
    public CommonData<MarketLog> queryAllLog(Integer page, Integer limit, String sort, String order,String name) {
        PageHelper.startPage(page,limit);
        MarketLogExample marketLogExample = new MarketLogExample();
        marketLogExample.setOrderByClause(sort + " " + order);
        MarketLogExample.Criteria criteria = marketLogExample.createCriteria();
        if (!StringUtils.isEmpty(name)) {
            criteria.andAdminLike("%"+name+"%");
        }
        List<MarketLog> marketLogs = marketLogMapper.selectByExample(marketLogExample);
        PageInfo<MarketLog> marketLogPageInfo = new PageInfo<>(marketLogs);
        CommonData data = CommonData.data(marketLogPageInfo);
        return data;
    }
}
